package org.internet.UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class ChatRoomReceiveDemo {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(10086);
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        while (true) {
            ds.receive(dp);
            byte[] data = dp.getData();
            int port = dp.getPort();
            InetAddress ip = dp.getAddress();
            String name = ip.getHostName();
            int len = dp.getLength();
            System.out.println(new String(data));
            System.out.println(ip.getHostAddress());
            System.out.println(port);
            System.out.println(name);
        }
        //ds.close();
    }
}
